/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package creditcard;

/**
 *
 * @author Matrix
 */
class CreditCard {
    private String number;
    private int validThrue;
    private String name;
    private String bank;
    private double balance;
    private int limit;
    private static int absNumber;
    CreditCard(String curNumber, String curName, String curBank, double curBalance, int curLimit) {
        absNumber += 1;
        System.out.println(absNumber);
        number = curNumber;
        name = curName;
        bank = curBank;
        balance = curBalance;
        limit = curLimit;
    }
    public String getNumber() {
        return number;
    }
    public String getName() {
        return name;
    }
    public String getBank() {
        return bank;
    }
    public Double getBalance() {
        return balance;
    }
    public void prnBalance() {
        System.out.println("Текущий баланс: " + balance);
    }
    public void doPayment(double pay) {
        if (pay > 0) {
            balance -= pay;
            prnBalance();
        }
        else {
            System.out.println("Incorrect price, pay must be > 0");
        }


    }
    public boolean doCharge(double price) {
        if (price < 0) {
            System.out.println("Incorrect price, price not to be < 0");
            return false;
        }
        if (balance + price <= limit) {
            balance += price;
            prnBalance();
            return true;
        }
        else {
            System.out.println("Превышен лимит");
            prnBalance();
            return false;
        }
    }
    public static void printCard(CreditCard crCard) {
        System.out.println("");
        System.out.println("Number: "+ crCard.number);
        System.out.println("Name: "+ crCard.name);
        System.out.println("Bank: "+ crCard.bank);
        System.out.println("Balance: "+ crCard.balance);
        System.out.println("Limit: "+ crCard.limit);
        
    }
    public static int getAbsNumber() {
        return absNumber;
    }
}
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        CreditCard wallet[] = new CreditCard[4];
        wallet[0] = new CreditCard("3910 4375 9387 5309",
        "JohnBowman", "CalforniaSavings", 0.0, 2500);
        wallet[1] = new CreditCard("3485 0399 3395 1954",
        "JohnBowman", "CalforniaFederal", 0.0, 3500);
        wallet[2] = new CreditCard("6011 4902 3294 2994",
        "JohnBowman", "CalforniaFinance", 0.0, 5000);
        for (int i = 1; i < 16; i++) {
            wallet[0].doCharge(i);
            wallet[1].doCharge(i*2);
            wallet[2].doCharge(-i*300);
        }
        for (int i = 0; i < 3; i++) {
            CreditCard.printCard(wallet[i]);
        }
        System.out.println("");
        for (int i = 0; i < 3; i++) {
            while (wallet[i].getBalance() > 0) {
                wallet[i].doPayment(100);
            }
        }


        /* int arr[] = new int[4];
        for (int i = 0; i < 4; i++) {
            creditCardPool[i] = new CreditCard();
            System.out.println(creditCardPool[i].getNumber());
            System.out.println(arr[i]);
            System.out.println("------------------");
        }
        System.out.println(CreditCard.getAbsNumber()); */

    }

}
